<?php

namespace Balance\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class BalanceController extends AbstractActionController
{
    protected $balanceTable;
    protected $balance;

    public function getBalanceTable()
    {
        if (!$this->balanceTable) {
            $sm = $this->getServiceLocator();
            $this->balanceTable = $sm->get('Balance\Model\BalanceTable');
        }
        return $this->balanceTable;
    }

    public function indexAction()
    {
        $this->balance = $this->getBalanceTable()->fetchAll();
        $view = new ViewModel(array(
            'balance' => $this->balance
        ));
        return $view;
    }
}